//
//  HWReadRecordHeadView.m
//  嗨文
//
//  Created by 响当当 on 2019/2/18.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWCashDrawHeadView.h"
#import "HWCashWithdrawalDetailViewController.h"

@interface HWCashDrawHeadView()
@property (nonatomic, strong)UILabel *drawMoneyTotleLabel;//已提现总奖励
@property (nonatomic, strong)UILabel *ableDrawMoneyLabel;//可提现
@property (nonatomic, strong)UIView *lineViewOne;
@property (nonatomic, strong)UIView *lineViewTwo;
@property (nonatomic, strong)UIView *lineViewThree;
@property (nonatomic, strong)UIView *lineViewFour;

@property (nonatomic, strong)NSMutableArray *buttonArr;
@end

@implementation HWCashDrawHeadView

- (NSMutableArray *)buttonArr
{
    if (!_buttonArr)
    {
        _buttonArr = [[NSMutableArray alloc]init];
    }
    return _buttonArr;
}

- (UILabel *)drawMoneyTotleLabel
{
    if (!_drawMoneyTotleLabel)
    {
        _drawMoneyTotleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,60*kUIScaleBasePlus,SCREEN_WIDTH,37*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentCenter
                                                      textClor:LCHexColor(0x333333)
                                                      textFont:18*kUIScaleBasePlus];
        _drawMoneyTotleLabel.numberOfLines = 0;
        _drawMoneyTotleLabel.text = @"0";

    }
    return _drawMoneyTotleLabel;
}

- (UILabel *)ableDrawMoneyLabel
{
    if (!_ableDrawMoneyLabel)
    {
        _ableDrawMoneyLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,130*kUIScaleBasePlus,SCREEN_WIDTH,60*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentCenter
                                                      textClor:LCHexColor(0xF54337)
                                                      textFont:30*kUIScaleBasePlus];
        _ableDrawMoneyLabel.numberOfLines = 0;
        _ableDrawMoneyLabel.text = @"0";
    }
    return _ableDrawMoneyLabel;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        [self creatUI];
    }
    return self;
}

#pragma mark - UI
- (void)creatUI
{
    UIButton *drawMoneyRecordBtn = [HWUtilties creatButtonWithFrame:CGRectMake(296*kUIScaleBasePlus,20*kUIScaleBasePlus,64*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                 textAligment:NSTextAlignmentLeft
                                                         text:@"提现记录"
                                                     textClor:LCHexColor(0x6E6E6E)
                                                    buttonBGC:[UIColor clearColor]
                                                     textFont:12*kUIScaleBasePlus
                                                       target:self
                                                       method:@selector(drawMoneyRecord)];
    [drawMoneyRecordBtn setImage:[UIImage imageNamed:@"withdrawal_record"] forState:UIControlStateNormal];
    [drawMoneyRecordBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,3,0,0)];
//    [self addSubview:drawMoneyRecordBtn];
    
    [self addSubview:self.drawMoneyTotleLabel];
    
    [self addSubview:self.ableDrawMoneyLabel];
    
    UIButton *drawMoneyBtn = [HWUtilties creatButtonWithFrame:CGRectMake(90*kUIScaleBasePlus,210*kUIScaleBasePlus,196*kUIScaleBasePlus,40*kUIScaleBasePlus)
                                                 textAligment:NSTextAlignmentCenter
                                                         text:@"提现"
                                                     textClor:LCHexColor(0xFFFFFF)
                                                    buttonBGC:LCHexColor(0xF54337)
                                                     textFont:16*kUIScaleBasePlus
                                                       target:self
                                                       method:@selector(drawMoney)];
    drawMoneyBtn.layer.masksToBounds = YES;
    drawMoneyBtn.layer.cornerRadius = 4;
    [self addSubview:drawMoneyBtn];
    
    UILabel *titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(16*kUIScaleBasePlus,280*kUIScaleBasePlus,120*kUIScaleBasePlus,13*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentLeft
                                                 textClor:LCHexColor(0x1F1F1F)
                                                 textFont:13*kUIScaleBasePlus];
    titleLabel.text = @"我的嗨友军团";
    [self addSubview:titleLabel];
    
    UIView *bkView = [[UIView alloc]initWithFrame:CGRectMake(0,303*kUIScaleBasePlus,SCREEN_WIDTH,50*kUIScaleBasePlus)];
    bkView.backgroundColor = LCHexColor(0xF5F5F5);
    [self addSubview:bkView];
    
    UIButton *segmentOneBtn = [HWUtilties creatButtonWithFrame:CGRectMake(0,0,SCREEN_WIDTH/4,48*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentCenter
                                                          text:@"嗨1"
                                                      textClor:LCHexColor(0xF54337)
                                                     buttonBGC:[UIColor clearColor]
                                                      textFont:15*kUIScaleBasePlus
                                                        target:self
                                                        method:@selector(segmentClcik:)];
    segmentOneBtn.tag = 0;
    [self.buttonArr addObject:segmentOneBtn];
    [bkView addSubview:segmentOneBtn];
    
    self.lineViewOne = [[UIView alloc]initWithFrame:CGRectMake(20*kUIScaleBasePlus,48*kUIScaleBasePlus,50*kUIScaleBasePlus,2*kUIScaleBasePlus)];
    self.lineViewOne.backgroundColor = LCHexColor(0xF54337);
    self.lineViewOne.hidden = NO;
    [bkView addSubview:self.lineViewOne];
    
    
    UIButton *segmentTwoBtn = [HWUtilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(segmentOneBtn.frame),0,SCREEN_WIDTH/4,48*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentCenter
                                                          text:@"嗨2"
                                                      textClor:LCHexColor(0x1F1F1F)
                                                     buttonBGC:[UIColor clearColor]
                                                      textFont:15*kUIScaleBasePlus
                                                        target:self
                                                        method:@selector(segmentClcik:)];
    segmentTwoBtn.tag = 1;
    [self.buttonArr addObject:segmentTwoBtn];
    [bkView addSubview:segmentTwoBtn];
    
    self.lineViewTwo = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(segmentOneBtn.frame)+20*kUIScaleBasePlus,48*kUIScaleBasePlus,50*kUIScaleBasePlus,2*kUIScaleBasePlus)];
    self.lineViewTwo.backgroundColor = LCHexColor(0xF54337);
    self.lineViewTwo.hidden = YES;
    [bkView addSubview:self.lineViewTwo];
    
    
    UIButton *segmentThreeBtn = [HWUtilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(segmentTwoBtn.frame),0,SCREEN_WIDTH/4,48*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentCenter
                                                          text:@"嗨3"
                                                      textClor:LCHexColor(0x1F1F1F)
                                                     buttonBGC:[UIColor clearColor]
                                                      textFont:15*kUIScaleBasePlus
                                                        target:self
                                                        method:@selector(segmentClcik:)];
    segmentThreeBtn.tag = 2;
    [self.buttonArr addObject:segmentThreeBtn];
    [bkView addSubview:segmentThreeBtn];
    
    self.lineViewThree = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(segmentTwoBtn.frame)+20*kUIScaleBasePlus,48*kUIScaleBasePlus,50*kUIScaleBasePlus,2*kUIScaleBasePlus)];
    self.lineViewThree.backgroundColor = LCHexColor(0xF54337);
    self.lineViewThree.hidden = YES;
    [bkView addSubview:self.lineViewThree];
    
    
    UIButton *segmentFourBtn = [HWUtilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(segmentThreeBtn.frame),0,SCREEN_WIDTH/4,48*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentCenter
                                                          text:@"团队"
                                                      textClor:LCHexColor(0x1F1F1F)
                                                     buttonBGC:[UIColor clearColor]
                                                      textFont:15*kUIScaleBasePlus
                                                        target:self
                                                        method:@selector(segmentClcik:)];
    segmentFourBtn.tag = 3;
    [self.buttonArr addObject:segmentFourBtn];
    [bkView addSubview:segmentFourBtn];
    
    self.lineViewFour = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(segmentThreeBtn.frame)+20*kUIScaleBasePlus,48*kUIScaleBasePlus,50*kUIScaleBasePlus,2*kUIScaleBasePlus)];
    self.lineViewFour.backgroundColor = LCHexColor(0xF54337);
    self.lineViewFour.hidden = YES;
    [bkView addSubview:self.lineViewFour];
}


#pragma mark - Method
- (void)segmentClcik:(UIButton *)sender
{
    NSInteger tag = sender.tag;
    
    if (self.getBackSegmentChangeBlock)
    {
        self.getBackSegmentChangeBlock([NSString stringWithFormat:@"%ld",tag]);
    }
    
    [self.buttonArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *btn = obj;
        if (tag == idx)
        {
            if (idx == 0)
            {
                self.lineViewOne.hidden = NO;
            }
            else if(idx == 1)
            {
                self.lineViewTwo.hidden = NO;
            }
            else if(idx == 2)
            {
                self.lineViewThree.hidden = NO;
            }
            else
            {
                self.lineViewFour.hidden = NO;
            }
            
            [btn setTitleColor:LCHexColor(0xF54337) forState:UIControlStateNormal];

        }
        else
        {
            switch (idx)
            {
                case 0:
                {
                    self.lineViewOne.hidden = YES;
                }
                    break;
                case 1:
                {
                    self.lineViewTwo.hidden = YES;
                }
                    break;
                case 2:
                {
                    self.lineViewThree.hidden = YES;
                }
                    break;
                case 3:
                {
                    self.lineViewFour.hidden = YES;
                }
                    break;
                default:
                    break;
            }
            [btn setTitleColor:LCHexColor(0x1F1F1F) forState:UIControlStateNormal];
        }
    }];
}

//提现记录
- (void)drawMoneyRecord
{
    
}

//提现
- (void)drawMoney
{
    HWCashWithdrawalDetailViewController *vc = [[HWCashWithdrawalDetailViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
}

#pragma mark - 获取数据
- (void)getDate:(NSDictionary *)dic
{
    NSString *drawMoneyStr = dic[@"draw"];
    self.drawMoneyTotleLabel.attributedText = [drawMoneyStr addAttriButedString:drawMoneyStr Color:LCHexColor(0x6E6E6E) Font:[UIFont systemFontOfSize:12*kUIScaleBasePlus] rang:NSMakeRange(drawMoneyStr.length-6,6)];
    
    NSString *drawMoneyAbleStr = dic[@"ableDraw"];
    self.ableDrawMoneyLabel.attributedText = [drawMoneyAbleStr addAttriButedString:drawMoneyAbleStr Color:LCHexColor(0x6E6E6E) Font:[UIFont systemFontOfSize:12*kUIScaleBasePlus] rang:NSMakeRange(drawMoneyAbleStr.length-5,5)];

}

- (void)getDateSegmentNum:(NSDictionary *)dic
{
    [self.buttonArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *btn = obj;
        switch (idx)
        {
            case 0:
            {
                [btn setTitle:[NSString stringWithFormat:@"嗨1(%@)",dic[@"upper"]] forState:UIControlStateNormal];
            }
                break;
            case 1:
            {
                [btn setTitle:[NSString stringWithFormat:@"嗨2(%@)",dic[@"lower"]] forState:UIControlStateNormal];
            }
                break;
            case 2:
            {
                [btn setTitle:[NSString stringWithFormat:@"嗨3(%@)",dic[@"third"]] forState:UIControlStateNormal];
            }
                break;
            case 3:
            {
                [btn setTitle:[NSString stringWithFormat:@"团队(%@)",dic[@"fourth"]] forState:UIControlStateNormal];
            }
                break;
            default:
                break;
        }
    }];
}
@end
